[POWERPC][XEN] More Robust Memory Checking
authorJimi Xenidis <jimix@watson.ibm.com>
Thu, 7 Sep 2006 05:30:12 +0000 (01:30 -0400)
committerJimi Xenidis <jimix@watson.ibm.com>
Thu, 7 Sep 2006 05:30:12 +0000 (01:30 -0400)
This patch allows the platform to define the "IO Hole" of
addressibility and checks that even Dom0 does not try to Map "Remote"
memory that is not there.  Also replaces some panic calls with WARN();
and returns failure.

Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
xen/arch/powerpc/mm.c
xen/arch/powerpc/powerpc64/ppc970.c
xen/arch/powerpc/usercopy.c
xen/include/asm-powerpc/mm.h
xen/include/asm-powerpc/processor.h

index 1014c041cf5973b4e901f3b24791c1a58c6a4557..3a8e103a506ca68037a51d1dcaa28a461aeae8e4 100644 (file)
@@ -229,16 +229,6 @@ extern void copy_page(void *dp, void *sp)
     }
 }
 
-static int mfn_in_hole(ulong mfn)
-{
-    /* totally cheating */
-    if (mfn >= (0xf0000000UL >> PAGE_SHIFT) &&
-        mfn < (((1UL << 32) - 1) >> PAGE_SHIFT))
-        return 1;
-
-    return 0;
-}
-
 static uint add_extent(struct domain *d, struct page_info *pg, uint order)
 {
     struct page_extents *pe;
@@ -339,7 +329,7 @@ int allocate_rma(struct domain *d, unsigned int order)
     return 0;
 }
 
-ulong pfn2mfn(struct domain *d, long pfn, int *type)
+ulong pfn2mfn(struct domain *d, ulong pfn, int *type)
 {
     ulong rma_base_mfn = page_to_mfn(d->arch.rma_page);
     ulong rma_size_mfn = 1UL << d->arch.rma_order;
@@ -356,7 +346,7 @@ ulong pfn2mfn(struct domain *d, long pfn, int *type)
     }
 
     if (test_bit(_DOMF_privileged, &d->domain_flags) &&
-        mfn_in_hole(pfn)) {
+        cpu_io_mfn(pfn)) {
         if (type)
             *type = PFN_TYPE_IO;
         return pfn;
@@ -374,7 +364,8 @@ ulong pfn2mfn(struct domain *d, long pfn, int *type)
 
     /* This hack allows dom0 to map all memory, necessary to
      * initialize domU state. */
-    if (test_bit(_DOMF_privileged, &d->domain_flags)) {
+    if (test_bit(_DOMF_privileged, &d->domain_flags) &&
+        pfn < max_page) {
         if (type)
             *type = PFN_TYPE_REMOTE;
         return pfn;
index d9f01b727f4f02af8bdf852e6dd30c852ad694e7..05fde31dec24f7d761f863512674d43b34c05d96 100644 (file)
@@ -88,6 +88,19 @@ unsigned int cpu_extent_order(void)
     return log_large_page_sizes[0] - PAGE_SHIFT;
 }
 
+
+/* This is more a platform thing than a CPU thing, but we only have
+ * one platform now */
+int cpu_io_mfn(ulong mfn)
+{
+    /* totally cheating */
+    if (mfn >= (2UL << (30 - PAGE_SHIFT)) && /* 2GiB */
+        mfn < (4UL << (30 - PAGE_SHIFT)))    /* 4GiB */
+        return 1;
+
+    return 0;
+}
+
 static u64 cpu0_hids[6];
 static u64 cpu0_hior;
 
index 8ac16e6c69fb50114948d8f63cc7d953fdc86fd3..0665052c39cb7832d1c87ad6b21fcbd965a7b2f7 100644 (file)
@@ -56,15 +56,21 @@ static unsigned long paddr_to_maddr(unsigned long paddr)
     case PFN_TYPE_RMA:
     case PFN_TYPE_LOGICAL:
         break;
+
     case PFN_TYPE_REMOTE:
+        /* I don't think this should ever happen, but I suppose it
+         * could be possible */
         printk("%s: Dom:%d paddr: 0x%lx type: REMOTE\n",
                __func__, d->domain_id, paddr);
         WARN();
         break;
+
+    case PFN_TYPE_IO:
     default:
-        panic("%s: Dom:%d paddr: 0x%lx bad type:0x%x\n",
+        printk("%s: Dom:%d paddr: 0x%lx bad type: 0x%x\n",
                __func__, d->domain_id, paddr, mtype);
-        break;
+        WARN();
+        return 0;
     }
     pa <<= PAGE_SHIFT;
     pa |= offset;
index 7f658ad417a27dc03f7d181b697824e7c763208f..320f33bcf1eab69d762e6c884854f03dc664b3a0 100644 (file)
@@ -241,7 +241,7 @@ extern int update_grant_va_mapping(unsigned long va,
 #define PFN_TYPE_IO 3
 #define PFN_TYPE_REMOTE 4
 
-extern ulong pfn2mfn(struct domain *d, long pfn, int *type);
+extern ulong pfn2mfn(struct domain *d, ulong pfn, int *type);
 
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg);
index 62a17545e67738e2b654e1b138de5cf3cfdd166e..0464010feef00336507e1044822160cfdf1c75d2 100644 (file)
@@ -46,6 +46,7 @@ extern int cpu_rma_valid(unsigned int log);
 extern uint cpu_large_page_orders(uint *sizes, uint max);
 extern void cpu_initialize(int cpuid);
 extern void cpu_init_vcpu(struct vcpu *);
+extern int cpu_io_mfn(ulong mfn);
 extern void save_cpu_sprs(struct vcpu *);
 extern void load_cpu_sprs(struct vcpu *);